{css href="/static/admin/css/style.css" /}
{layout name="layout"}

{include file="public/nav"}
<div class="container">
    <div class="container-fluid" style="text-align: center">
        <h1>全部文章</h1> <p>总共: {$total} 篇文章     每页: {$articles|count}篇</p>
    </div>

    <div class="container">

        {volist name="articles" id="article"}
        <div class="adminarticlelist row"
             style="position: relative;
             text-align: center;
         border: 1px solid black;
         border-radius: 10px;
         padding: 10px; margin: 5px;">
            <div class="col-md-3">
                <div class="calendar">
                    <p style="font-size: 20px">{$article.article_create_time|substr=8,3}</p>
                    <p>{$article.article_create_time|substr=0,7}</p>
                </div>
            </div>
            <div class="col-md-5">
                <p style="font-size: 18px;"> {$article.article_name} </p>
            </div>
            <div class="col-md-2">
                <button data-changearticle="{$article.article_id}" class="btn changearticle">
                    <a href="/admin/changeArticle/{$article.article_id}">修改</a>
                </button>
                <button data-delarticle="{$article.article_id}"  class="btn btn-danger delarticle">删除</button>
            </div>
            <div class="col-md-2">
                <form name="changeclass" id="changeClass" action="">
                    {$article.class_name}
                </form>
            </div>
        </div>
        {/volist}
        <div class="container" style="text-align: center">
            <div style="display: block; margin-right: 100px;">{$articles|raw}</div>
        </div>


</div>
</div>

<script>
    //    ajax 删除文章
    $(".delarticle").click(function () {
        let article = $(this);
        $.confirm({
            title: '确认',
            content: '确认删除该文章?',
            type: 'green',
            icon: 'glyphicon glyphicon-question-sign',
            buttons: {
                ok: {
                    text: '确认',
                    btnClass: 'btn-primary',
                    action: function() {
                        article.parent().parent().fadeOut()
                        $.ajax({
                            type: "POST",
                            url: '/admin/delArticle/'+article.attr("data-delarticle"),
                            success:function (data) {
                                if(data === 1){
                                    alert("删除成功！")
                                }else{
                                    alert("删除失败！")
                                    location.href = "/admin"
                                }
                            },
                            error:function (error) {
                                alert("删除失败！")
                                location.href = "/admin"
                                console.log(error);
                            }
                        })
                    }
                },
                cancel: {
                    text: '取消',
                    btnClass: 'btn-primary'
                }
            }
        });
    })


</script>

